<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户昵称" prop="formaluserId">
        <el-select v-model="queryParams.formaluserId" filterable placeholder="请选择" clearable>
          <el-option
            v-for="item in userList"
            :key="item.userId"
            :label="item.nickName"
            :value="parseInt(item.userId)"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="入职资料填写确认" prop="joinData" label-width="auto">
        <el-select v-model="queryParams.joinData" placeholder="请选择入职资料填写确认" clearable size="small">
          <el-option
            v-for="dict in dict.type.personnel_form_sign"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="劳动合同期限" label-width="auto">
        <el-date-picker
          v-model="daterangeAgreementDate"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="薪资确认单" prop="paySign" label-width="auto">
        <el-select v-model="queryParams.paySign" placeholder="请选择薪资确认单" clearable size="small">
          <el-option
            v-for="dict in dict.type.personnel_form_sign"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="实际转正日期" label-width="auto">
        <el-date-picker
          v-model="daterangeFormalDate"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['personnel:userformal:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['personnel:userformal:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['personnel:userformal:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['personnel:userformal:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userformalList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户昵称" align="center" prop="user.nickName" />
      <el-table-column label="工位安排" align="center" prop="position">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_seatnum" :value="scope.row.position"/>
        </template>
      </el-table-column>
      <el-table-column label="7天考核期得分" align="center" prop="sevendaysGrade" />
      <el-table-column label="入职资料填写" align="center" prop="joinData">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.personnel_form_sign" :value="scope.row.joinData"/>
        </template>
      </el-table-column>
      <el-table-column label="劳动合同期限" align="center" prop="agreementDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.agreementDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="社保缴纳时间" align="center" prop="socialSecurityDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.socialSecurityDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公积金缴纳时间" align="center" prop="accumulationFundDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.accumulationFundDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="薪资确认单" align="center" prop="paySign">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.personnel_form_sign" :value="scope.row.paySign"/>
        </template>
      </el-table-column>
      <el-table-column label="实际转正日期" align="center" prop="formalDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.formalDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="转正考核分数" align="center" prop="formalGrade" />
      <el-table-column label="协商试用期薪资" align="center" prop="probationPay" />
      <el-table-column label="协商转正薪资" align="center" prop="formalPay" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['personnel:userformal:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['personnel:userformal:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改转正信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="工位安排" prop="position">
          <el-select v-model="form.position" placeholder="请选择工位安排">
            <el-option
              v-for="dict in dict.type.sys_user_seatnum"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="7天考核期得分" prop="sevendaysGrade">
          <el-input v-model="form.sevendaysGrade" placeholder="请输入7天考核期得分" />
        </el-form-item>
        <el-form-item label="入职资料填写确认" prop="joinData">
          <el-select v-model="form.joinData" placeholder="请选择入职资料填写确认">
            <el-option
              v-for="dict in dict.type.personnel_form_sign"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="劳动合同期限" prop="agreementDate">
          <el-date-picker clearable size="small"
            v-model="form.agreementDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择劳动合同期限">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="社保缴纳时间" prop="socialSecurityDate">
          <el-date-picker clearable size="small"
            v-model="form.socialSecurityDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择社保缴纳时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公积金缴纳时间" prop="accumulationFundDate">
          <el-date-picker clearable size="small"
            v-model="form.accumulationFundDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择公积金缴纳时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="薪资确认单" prop="paySign">
          <el-select v-model="form.paySign" placeholder="请选择薪资确认单">
            <el-option
              v-for="dict in dict.type.personnel_form_sign"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="实际转正日期" prop="formalDate">
          <el-date-picker clearable size="small"
            v-model="form.formalDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际转正日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="转正考核分数" prop="formalGrade">
          <el-input v-model="form.formalGrade" placeholder="请输入转正考核分数" />
        </el-form-item>
        <el-form-item label="协商试用期薪资" prop="probationPay">
          <el-input v-model="form.probationPay" placeholder="请输入协商试用期薪资" />
        </el-form-item>
        <el-form-item label="协商转正薪资" prop="formalPay">
          <el-input v-model="form.formalPay" placeholder="请输入协商转正薪资" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUserformal, getUserformal, delUserformal, addUserformal, updateUserformal } from "@/api/personnel/userformal";
import { listUser } from "@/api/system/user";

export default {
  name: "Userformal",
  dicts: ['sys_user_seatnum', 'personnel_form_sign'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 转正信息管理表格数据
      userformalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 转正考核分数时间范围
      daterangeAgreementDate: [],
      // 转正考核分数时间范围
      daterangeFormalDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        formaluserId: null,
        joinData: null,
        agreementDate: null,
        paySign: null,
        formalDate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询转正信息管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeAgreementDate && '' != this.daterangeAgreementDate) {
        this.queryParams.params["beginAgreementDate"] = this.daterangeAgreementDate[0];
        this.queryParams.params["endAgreementDate"] = this.daterangeAgreementDate[1];
      }
      if (null != this.daterangeFormalDate && '' != this.daterangeFormalDate) {
        this.queryParams.params["beginFormalDate"] = this.daterangeFormalDate[0];
        this.queryParams.params["endFormalDate"] = this.daterangeFormalDate[1];
      }
      listUserformal(this.queryParams).then(response => {
        this.userformalList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.userList = response.rows;
        this.total1 = response.total;
      });


    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        formaluserId: null,
        position: null,
        sevendaysGrade: null,
        joinData: null,
        agreementDate: null,
        socialSecurityDate: null,
        accumulationFundDate: null,
        paySign: null,
        formalDate: null,
        formalGrade: null,
        probationPay: null,
        formalPay: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeAgreementDate = [];
      this.daterangeFormalDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加转正信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getUserformal(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改转正信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUserformal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUserformal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除转正信息管理编号为"' + ids + '"的数据项？').then(function() {
        return delUserformal(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('personnel/userformal/export', {
        ...this.queryParams
      }, `userformal_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
